version: '3.9'

services:
  db-init:
    image: postgres:14
    volumes:
      - ./blockscout-db-data:/var/lib/postgresql/data
    entrypoint:
      - sh
      - -c
      - |
        chown -R 2000:2000 /var/lib/postgresql/data

  db:
    depends_on:
      db-init:
        condition: service_completed_successfully
    image: postgres:14
    user: 2000:2000
    restart: always
    container_name: 'db'
    command: postgres -c 'max_connections=200' -c 'client_connection_check_interval=60000'
    environment:
        POSTGRES_DB: 'blockscout'
        POSTGRES_USER: 'blockscout'
        POSTGRES_PASSWORD: 'ceWb1MeLBEeOIfk65gU8EjF8'
    ports:
      - 7432:5432
    volumes:
      - ./blockscout-db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U blockscout -d blockscout"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
